package com.trg.designmodel.singleleton;

/**
 * @ClassName: SingleLetonTest01
 * @Description: 单例设计模式-饿汉式（静态常量）
 * @Author: tangrg
 * @Date: 2021/6/30 14:41
 * @Version: 1.0
 * @Return:
 **/
public class SingleLetonTest01 {
    public static void main(String[] args) {
        SingleLeton instance = SingleLeton.getInstance();
        SingleLeton instance2 = SingleLeton.getInstance();
        System.out.println(instance == instance2);
        System.out.println("instance:"+instance.hashCode());
        System.out.println("instance2:"+instance2.hashCode());

    }

}

class SingleLeton {
    //***1、私有化构造器
    private SingleLeton() {
    }

    //***2、类内部创建静态实例
    private final static SingleLeton instance = new SingleLeton();

    //***3、提供一个公有的静态方法，将实例对象返回
    public static SingleLeton getInstance() {
        return instance;
    }
}

